// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import Vuex from 'vuex'
import infiniteScroll from 'vue-infinite-scroll';
import RegisterPage from './components/RegisterPage'
import LoginPage from './components/LoginPage'
import HomeIndex from './components/HomeIndex'
import MyTao from './components/MyTao'
import ShopCart from './components/ShopCart'
import CollectionUp from './components/CollectionUp'
import ShopMessage from './components/ShopMessage'
import MySelf from './components/MySelf'
import PayMoney from './components/PayMoney'
import AddAddress from './components/AddAddress'
import WaitPay from './components/WaitPay'
import WaitGo from './components/WaitGo'
import WaitShou from './components/WaitShou'
import WaitPing from './components/WaitPing'
import AllShop from './components/AllShop'
import SellerShop from './components/SellerShop'
import GuanZhu from './components/GuanZhu'

import 'assets/font-awesome/css/font-awesome.min.css'
import axios from 'axios'
import '../src/validate.js'

Vue.prototype.$axios = axios;

Vue.use(VueRouter)
Vue.use(infiniteScroll);
Vue.use(Vuex);
const store = new Vuex.Store({
	state: {
		nickName: ''
	},
	mutations: {
		//更新用户信息
		updateUserInfo(state, nickName) {
			state.nickName = nickName;
		},

	}
});

const routes = [{
		path: '/register',
		component: RegisterPage
	},
	{
		path: '/login',
		component: LoginPage
	}, {
		path: '/',
		component: HomeIndex
	},
	{
		path: '/mytao',
		component: MyTao
	},
	{
		path: '/shopcart',
		component: ShopCart
	},
	{
		path: '/collection',
		component: CollectionUp
	},
	{
		path: '/shopmsg/:id',
		component: ShopMessage
	},
	{
		path: '/myself/:id',
		component: MySelf
	},
	{
		path: '/paymoney',
		component: PayMoney
	},
	{
		path: '/address',
		component: AddAddress
	},
	{
		path: '/waitpay',
		component: WaitPay
	},
	{
		path: '/waitgo',
		component: WaitGo
	},
	{
		path: '/waitshou',
		component: WaitShou
	},
	{
		path: '/waitping',
		component: WaitPing
	},
	{
		path: '/allshop',
		component: AllShop
	},
	{
		path: '/sellershop/:author',
		component: SellerShop
	},
	{
		path: '/guanzhu',
		component: GuanZhu
	},
]

const router = new VueRouter({
	routes
})

FastClick.attach(document.body)

new Vue({
	router,
	store,
	mounted() {
		this.checkLogin();
	},
	methods: {
		checkLogin() {
			var that = this;
			axios.get("/taobao/checkLogin").then(function(res) {
				var res = res.data;
				console.log(res);
				if(res.error == "0") {
					console.log('00')
					that.$store.commit("updateUserInfo", res.result);
				} 	
			})
		}
	},

	render: h => h(App)
}).$mount('#app')